<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start();
date_default_timezone_set('PRC'); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>xiajia</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <link href="demo.css" rel="stylesheet" type="text/css"/>
    <script src="scripts/boot.js" type="text/javascript"></script>
    <style>

    </style>

</head>
<body>

<fieldset id="fd1" style="border: 1px solid gray;height: 70px">
    <legend><span>下架操作</span></legend>
    <div id='fm1'>
        <div class="fieldset-body">
            客户代码:
            <div class="mini-autocomplete" style="width:250px;" popupWidth="400" textField="id" valueField="id"
                 id='Customer_Code' name='Customer_Code'
                 url="/sale/getOCRDByCode" value="<?php if (isset($_SESSION['u_code'])) {
                echo $_SESSION['u_code'];
            } ?>" text="<?php if (isset($_SESSION['u_code'])) {
                echo $_SESSION['u_code'];
            } ?>" onvaluechanged="onValueChanged">
                <div property="columns">
                    <div header="客户代码" field="id" width="30"></div>
                    <div header="客户名称" field="text"></div>
                </div>
            </div>


            客户名称: <input type="input" class='mini-textbox' id='cname-show' style="width: 250px"/>

            <span>添加日期：</span>
            <input id="start" class="mini-datepicker" format="yyyy-MM-dd " showTime="true" valueType='string'
                   value="<?php echo date('Y-m-d', time() - 86400 * 7) ?>"/>
            <input id="end" class="mini-datepicker" format="yyyy-MM-dd " showTime="true" valueType='string'
                   value="<?php echo date('Y-m-d ') ?>"/>

            <!--            筛选:<input id="s_type" class="mini-combobox" style="width:150px;" textField="text" valueField="id"-->
            <!--                      emptyText="请选择..."-->
            <!--                      data="[{id:0,text:'全部'},{id:1,text:'未失效'},{id:2,text:'已失效'}]" value="1" required="true"-->
            <!--                      allowInput="true" showNullItem="true" nullItemText="请选择..."/>-->
            <br/>
            <a class="mini-button" onclick="search()" enabled="" id='query-bt' style="margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a>
            <a class="mini-button" onclick="exportexcel()" enabled="" id='query-bt' style="margin-top: 5px">&nbsp;&nbsp;导出&nbsp;&nbsp;</a>
</fieldset>

<div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
     buttons="#tabsButtons"
>
    <div title="筛选:上架类型：0普通,1活动,2集采.">

        <div id="datagrid1" class="mini-datagrid" style="height:330px;width: 100%;"
             url="/goods/queryItemByCodeXiaJia" idField="id"
             allowResize="true" showFilterRow="true"
             allowCellEdit="true" allowCellSelect="true" multiSelect="true"
             allowCellValid="true" oncellvalidation="" onCellendedit='cellendedit'
        >

            <div property="columns">

                <div type="checkcolumn"></div>

                <div field="oa_id" headerAlign="center">OA物料号
                    <input class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="shelves_type" headerAlign="center" allowSort="true">上架类型
                    <input id="typeFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>

                <div field="shelves_list_name" headerAlign="center" allowSort="false">上架清单名
                    <input id="listnameFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>
                <div field="shelves_list_pm" headerAlign="center" allowSort="false">产品经理
                    <input id="productmFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>

                <div field="SAP_ItemCode" headerAlign="center">SAP物料号
                    <input id="sapitemcodeFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>

                <div field="SAP_ItemName" headerAlign="center" width='300px'>SAP物料名称
                    <input id="itemnameFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>

                <div field="qty" headerAlign="center">数量
                    <input  class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="BANK_Model" headerAlign="center">规格
                    <input class="mini-textbox" style="width:100%;"/>
                </div>

                <div field="BANK_ItemCode" headerAlign="center">平台商品代码
                    <input id="bankitemcodeFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>

                <!--                <div field="BANK_FroTime" headerAlign="center">上架时间-->
                <!--                    <input class="mini-datepicker" valueType='string' style="width:100%;"-->
                <!--                           format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true"/>-->
                <!--                </div>-->
                <!---->
                <!--                <div field="BANK_ToTime" headerAlign="center">下架时间-->
                <!--                    <input class="mini-datepicker" valueType='string' style="width:100%;"-->
                <!--                           format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true"/>-->
                <!--                </div>-->

                <div field="create_time" headerAlign="center">上架时间</div>

                <div field="pcode"  width="100px">主品物料号
                    <input id="pcodeFilter" property="filter" class="mini-textbox" style="width:100%;"
                           onvaluechanged="onFilterChanged"
                    />
                </div>

                <div field="color"  width="50px">颜色
                    <input class="mini-textbox" style="width:100%;"/>
                </div>
                <!--<div field="BANK_Model" headerAlign="center">规格-->
                <!--<input class="mini-textbox" style="width:100%;"/>-->
                <!--</div>-->

                <div field="maoli"  width="50px">毛利
                    <input class="mini-textbox"/>
                </div>

                <div field="mall_price"  width="50px">商城价
                    <input class="mini-textbox"/>
                </div>
                <!--<div field="market_price"  width="50px">市场价-->
                <!--<input  class="mini-textbox"/>-->
                <!--</div>-->

                <div field="maolilv"  width="50px">毛利率
                    <input class="mini-textbox"/>
                </div>

                <div field="purchase_price"  width="50px">采购价
                    <input class="mini-textbox"/>
                </div>
                <div field="by_stages"  width="50px">分期数
                    <input class="mini-textbox"/>
                </div>
                <div field="by_stages_rate"  width="50px">分期费率(%)
                    <input class="mini-textbox"/>
                </div>

                <div field="freight"  width="50px">预估运费
                    <input  class="mini-textbox"/>
                </div>

                <div field="gift_price"  width="50px">赠品价格
                    <input  class="mini-textbox"/>
                </div>

                <div field="bank_commission"  width="50px">佣金
                    <input class="mini-textbox"/>
                </div>

                <div field="zengzhishui"  width="50px">增值税等17%
                    <input class="mini-spinner"/>
                </div>

                <div field="packing_charge"  width="50px">包装费
                    <input  class="mini-textbox"/>
                </div>

                <div field="rebate"  width="50px">返利金额
                    <input  class="mini-textbox"/>
                </div>

                <!--                Attachment begin-->

                <div field="tamll_price"  width="100px">天猫价
                    <input  class="mini-textbox"/>
                </div>
                <div field="tamll_S_AMT"  width="100px">天猫销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="tamll"  width="100px">天猫
                    <input  class="mini-textbox"/>
                </div>

                <div field="jd_price"  width="100px">京东价
                    <input  class="mini-textbox"/>
                </div>
                <div field="jd_S_AMT"  width="100px">京东销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="jd"  width="100px">京东
                    <input  class="mini-textbox"/>
                </div>

                <div field="guangfa_price"  width="100px">广发价
                    <input  class="mini-textbox"/>
                </div>
                <div field="guangfa_S_AMT"  width="100px">广发销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="guangfa"  width="100px">广发
                    <input  class="mini-textbox"/>
                </div>

                <div field="jianhang_price"  width="100px">建行价
                    <input  class="mini-textbox"/>
                </div>
                <div field="jianhang_S_AMT"  width="100px">建行销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="jianhang"  width="100px">建行
                    <input  class="mini-textbox"/>
                </div>

                <div field="zhaohang_price"  width="100px">招行价
                    <input  class="mini-textbox"/>
                </div>
                <div field="zhaohang_S_AMT"  width="100px">招行销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="zhaohang"  width="100px">招行
                    <input  class="mini-textbox"/>
                </div>

                <div field="jiaohang_price"  width="100px">交行价
                    <input  class="mini-textbox"/>
                </div>
                <div field="jiaohang_S_AMT"  width="100px">交行销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="jiaohang"  width="100px">交行
                    <input  class="mini-textbox"/>
                </div>

                <div field="minsheng_price"  width="100px">民生价
                    <input  class="mini-textbox"/>
                </div>
                <div field="minsheng_S_AMT"  width="100px">民生销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="minsheng"  width="100px">民生
                    <input  class="mini-textbox"/>
                </div>

                <div field="pingan_price"  width="100px">平安价
                    <input  class="mini-textbox"/>
                </div>
                <div field="pingan_S_AMT"  width="100px">平安销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="pingan"  width="100px">平安
                    <input  class="mini-textbox"/>
                </div>

                <div field="zhongxin_price"  width="100px">中信价
                    <input  class="mini-textbox"/>
                </div>
                <div field="zhongxin_S_AMT"  width="100px">中信销量
                    <input  class="mini-textbox"/>
                </div>
                <div field="zhongxin"  width="100px">中信
                    <input  class="mini-textbox"/>
                </div>

                <div field="remark"  width="100px">备注
                    <input property="editor" class="mini-textbox"/>
                </div>

                <!--                Attachment end-->

                <!--                <div name="action" width="100" headerAlign="center">#</div>-->
            </div>
        </div>

    </div>
    <!-- <div title="Tab2" iconCls="" >
        2
    </div> -->
</div>

<div id='editForm1'>
    <a class="mini-button" onclick="save()" enabled="" id=''>&nbsp;&nbsp;下架&nbsp;&nbsp;</a>
</div>
</body>
<script type="text/javascript">
    mini.parse();
    var grid = mini.get("datagrid1");
    grid.setPageSize(50);
    search();
    grid.on("drawcell", function (e) {
        var record = e.record,
            column = e.column,
            field = e.field,
            value = e.value;

        //格式化日期
        if (field == "BANK_FroTime" || field == 'BANK_ToTime') {
            if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");

        }

        if (field == "oa_id") {
            e.cellHtml = '<a href="/SapSupplier/itemshow/id/'+value+'" target=_blank>'+value+'</a>&nbsp; ';
        }

        if (field == "shelves_type") {

            if(value == 0) {
                e.cellHtml = '普通';
            }else if (value == 1){
                e.cellHtml = '活动';
            }else if (value == 2){
                e.cellHtml = '集采';
            }

        }

        if(record.pcode)
            e.cellStyle = "background:#94bad5";

        //action列，超连接操作按钮
        if (column.name == "action") {
            e.cellStyle = "text-align:center";
            e.cellHtml = '<a href="/sap/goods_gift_time.php?gid=' + record.id + '"/>关联赠品</a>&nbsp; ';

        }

    });

    function search() {

        var start = mini.get('start').getValue();
        var end = mini.get('end').getValue();
        var code = mini.get('Customer_Code').getValue();
        //var s_type = mini.get('s_type').getValue(); //筛选
        grid.load({'code': code, 'start': start, 'end': end});
    }

    function exportexcel() {

        var start = mini.get('start').getValue();
        var end = mini.get('end').getValue();
        var code = mini.get('Customer_Code').getValue();

        self.location.href="/goods/exportexcelsapbankrelationXiaJia/start/"+start+"/end/"+end+"/code/"+code;

//        $.ajax({
//            url: "/goods/exportexcelsapbankrelation",
//            data: {'code': code, 'start': start, 'end': end},
//            type: "post",
//            dataType: 'json',
//            success: function (data) {
//            },
//            error: function (jqXHR, textStatus, errorThrown) {
//                alert(jqXHR.responseText);
//            }
//        });

    }

    function onButtonEdit(e) {
        var btnEdit = this;
        mini.open({
            url: "/sap/goods_select.php",
            title: "选择物料",
            width: 650,
            height: 380,
            ondestroy: function (action) {
                //if (action == "close") return false;
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.GetData();
                    data = mini.clone(data);    //必须
                    if (data) {
                        data.Customer_Code = mini.get('Customer_Code').getValue();
                        data.SAP_ItemCode = data.catid;
                        data.SAP_ItemName = data.name;
                        data.BANK_Model = data.BANK_Model;
                        grid.addRow(data, 0);

                    }
                }

            }
        });
    }

//    function save() {
//        var data = grid.getChanges()[0];
//        if (data == null) {
//            mini.alert('无更新数据');
//            return;
//        }
//
//        if (data.BANK_FroTime == null || data.BANK_ToTime == null) {
//            mini.alert('上下架时间不能为空');
//            return;
//        }
//
//        var form = new mini.Form("#fm1");
//        var fmdata = form.getData();      //获取表单多个控件的数据
//        if (data.Customer_Code == '') {
//            data.Customer_Code = fmdata.Customer_Code;
//        }
//
//
//        if (data.Customer_Code == '') {
//            mini.alert('请选择客户');
//            return;
//        }
//        var json = mini.encode(data);
//        //alert(json);
//        mini.mask({
//            el: document.body,
//            cls: 'mini-mask-loading',
//            html: '保存中...'
//        });
//        $.ajax({
//            url: "/goods/saveRelation",
//            data: {data: json},
//            type: "post",
//            dataType: 'json',
//            success: function (data) {
//                if (data.code == 0) {
//                    mini.unmask(document.body);
//                    mini.alert('保存成功!');
//                    search();
//                    return;
//                } else {
//                    mini.unmask(document.body);
//                    mini.alert(data.msg);
//                }
//            },
//            error: function (jqXHR, textStatus, errorThrown) {
//                alert(jqXHR.responseText);
//            }
//        });
//    }


    function onValueChanged(e) {

        var item = e.selected;
        if (item) {
            mini.get('cname-show').setValue(item.text);
        }
    }

</script>

<script type="text/javascript">
    function onFilterChanged(e) {

        var typebox = mini.get("typeFilter");
        var listnamebox = mini.get("listnameFilter");
        var productmbox = mini.get("productmFilter");
        var itemnamebox = mini.get("itemnameFilter");
        var pcodebox = mini.get("pcodeFilter");
        var sapitemcodebox = mini.get("sapitemcodeFilter");
        var bankitemcodebox = mini.get("bankitemcodeFilter");

        var type = typebox.getValue().toLowerCase();
        var listname = listnamebox.getValue().toLowerCase();
        var productm = productmbox.getValue().toLowerCase();
        var itemname = itemnamebox.getValue().toLowerCase();
        var pcode = pcodebox.getValue().toLowerCase();
        var sapitemcode = sapitemcodebox.getValue().toLowerCase();
        var bankitemcode = bankitemcodebox.getValue().toLowerCase();

        //多条件组合过滤
        grid.filter(function (row) {

            //type
            var r1 = true;
            if (type) {
                r1 = String(row.shelves_type).toLowerCase().indexOf(type) != -1;
            }

            //product_m
            var r3 = true;
            if (productm) {
                r3 = String(row.shelves_list_pm).toLowerCase().indexOf(productm) != -1;
            }

            //list_name
            var r4 = true;
            if (listname) {
                r4 = String(row.shelves_list_name).toLowerCase().indexOf(listname) != -1;
            }

            //itemname
            var r5 = true;
            if (itemname) {
                r5 = String(row.SAP_ItemName).toLowerCase().indexOf(itemname) != -1;
            }

            //pcode
            var r6 = true;
            if (pcode) {
                r6 = String(row.pcode).toLowerCase().indexOf(pcode) != -1;
            }

            //sapitemcode
            var r7 = true;
            if (sapitemcode) {
                r7 = String(row.SAP_ItemCode).toLowerCase().indexOf(sapitemcode) != -1;
            }

            //bankitemcode
            var r2 = true;
            if (bankitemcode) {
                r2 = String(row.BANK_ItemCode).toLowerCase().indexOf(bankitemcode) != -1;
            }

            return r1 && r3 && r4 && r5 && r6 && r7 && r2;

        });
    }

</script>

<script language="JavaScript">
    function save() {
        var data = grid.getSelecteds();
        for (var i = 0; i < data.length; i++) {

            if (data[i].check == 0) {
                mini.alert('请修改错误数据后保存！');
                return;
            }

        }

        var form = new mini.Form("#fm1");
        var fmdata = form.getData();      //获取表单多个控件的数据

        if (fmdata.Customer_Code == '') {
            mini.alert('请选择客户');
            return;
        }

        var postData = {data: data, Customer_Code: fmdata.Customer_Code}
        var json = mini.encode(postData);

        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '保存中...'
        });


        $.ajax({
            url: "/goods/doXiaJia",
            data: {data: json},
            type: "post",
            dataType: 'json',
            success: function (data) {
                if (data.code > 0) {
                    mini.unmask(document.body);
                    if (data.msg != null) {
                        mini.alert(data.msg);
                    } else {
                        mini.alert('操作成功');

                    }
                    return;
                } else {
                    mini.unmask(document.body);
                    mini.alert(data.msg);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }

    function cellendedit(e) {
            column = e.column,
            field = e.field,
            value = e.value;

        if (e.record._state != null) {
            update(mini.encode(e.record));
        }
    }

    function update(data) {

        $.ajax({
            url: "/Shelves/updateShelvesDetailedRemarkForXiaJia",
            type: "post",
            data: {
                data: data
            },
            dataType: 'json',
            success: function (data) {
            }
        });
    }

</script>

</html>